home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / fly8str.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  3KB  |  144 lines

  1. /* --------------------------------- fly8str.c ------------------------------ */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* This is the Fly8 driver for editstr(). Fly8 is running in the
  8.  * background so it will display the partially edited string as long
  9.  * as edit_str is active. The output callback is dummied out for this
  10.  * reason (except for the beep).
  11. */
  12.  
  13. #include "fly.h"
  14.  
  15.  
  16. /* These functions are call-backs from editstr().
  17. */
  18.  
  19. static void * FAR
  20. e_malloc (int n)
  21. {
  22.     return (memory_alloc (n));
  23. }
  24.  
  25. static void * FAR
  26. e_free (void *p, int n)
  27. {
  28.     memory_free (p, n);
  29.     return (NULL);
  30. }
  31.  
  32. /* Put a character to the output device.
  33. */
  34. static void FAR
  35. e_put (int ch)
  36. {
  37.     if ('\a' == ch && st.quiet)
  38.         Snd->Effect (EFF_BEEP, SND_ON);
  39. }
  40.  
  41. /* Get a character from the input device.
  42. */
  43. static int FAR
  44. e_get (void)
  45. {
  46.     return (mgetch ());
  47. }
  48.  
  49. /* Set cursor shape to indicate insert/overtype mode.
  50. */
  51. static void FAR
  52. e_show (int edit_mode)
  53. {}
  54.  
  55.  
  56.  
  57.  
  58. /* Called by Fly8 to initialise editstr().
  59. */
  60. extern int FAR
  61. edit_init (void)
  62. {
  63.     return (editset (e_malloc, e_free, e_put, e_get, e_show,
  64.         3, st.maxrecall));
  65. }
  66.  
  67. /* Called by Fly8 to terminate editstr().
  68. */
  69. extern int FAR
  70. edit_term (void)
  71. {
  72.     return (editstr (NULL, 0));
  73. }
  74.  
  75. static char    FAR* Prompt = 0;
  76.  
  77. /* Called by Fly8 to access editstr().
  78. */
  79. extern int FAR
  80. edit_str (char *prompt, char FAR* str, int len)
  81. {
  82.     int    ret;
  83.  
  84.     Prompt = prompt;
  85.     ret = editstr (str, len);
  86.     Prompt = 0;
  87.     return (ret);
  88. }
  89.  
  90. /* display the prompt and the user input if editstr() is active.
  91. */
  92. extern void FAR
  93. edit_show (VIEW *view, int orgx, int orgy, int maxx, int maxy, int bss)
  94. {
  95.     int    i, x, dx, xl, xr, y, tick;
  96.     char    *p;
  97.     char    *str;
  98.     int    len, pos, mode;
  99.  
  100.     if (!Prompt)
  101.         return;
  102.  
  103.     dx = stroke_size ("x", bss);
  104.     tick = bss/2;
  105.  
  106.     xl = orgx - maxx + bss + 2;
  107.     xr = orgx + maxx - bss - 2;
  108.     y = orgy + maxy - 4;
  109.  
  110.     gr_color (CC_LGRAY);
  111.     gr_move (xl-2,   y+2);
  112.     gr_draw (xr+bss, y+2);
  113.     gr_draw (xr+bss, y-1-bss);
  114.     gr_draw (xl-2,   y-1-bss);
  115.     gr_draw (xl-2,   y+2);
  116.  
  117.     x = xl;
  118.     if (*Prompt) {
  119.         for (p = Prompt; *p; ++p)
  120.             x += stroke_char (x, y, *p,  bss, CC_LGRAY);
  121.         x += dx;
  122.     }
  123.  
  124.     editget (&str, &len, &pos, &mode);
  125.  
  126.     for (i = 0;; ++i) {
  127.         if (i == pos) {
  128.             gr_color (CC_WHITE);
  129.             gr_move (x, y+3);
  130.             gr_draw (x, y-2-bss);
  131.             if (mode) {
  132.                 gr_move (x-tick, y-2-bss-tick);
  133.                 gr_draw (x,      y-2-bss);
  134.                 gr_draw (x+tick, y-2-bss-tick);
  135.             }
  136.         }
  137.         if (i >= len)
  138.             break;
  139.         if (x > xr)
  140.             break;
  141.         x += stroke_char (x, y, str[i], bss, CC_WHITE);
  142.     }
  143. }
  144.